<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="centre/manage/include :: header">
</head>

<link rel="stylesheet" type="text/css"
	href="/css/plugins/layui/layui.css" />
	<link href="/css/jquery-select/jquery.searchableSelect.css" rel="stylesheet" type="text/css">
<style>
.province {
	float: left;
	position: relative;
	width: 150px;
	height: 35px;
	line-height: 35px;
	border: 1px solid #fff;
}

.province:hover {
	border: 1px solid #f7e4a5;
	border-bottom: 1px solid #fffec6;
	background: #fffec6;
}

.province .cityall {
	margin-top: 10px;
}

.province ul {
	list-style: outside none none;
	position: absolute;
	padding: 0;
	background: #fffec6;
	border: 1px solid #f7e4a5;
	display: none;
	width: auto;
	width: 300px;
	z-index: 999999;
	left: -26px;
	top: 33px;
}

.province ul li {
	float: left;
	min-width: 60px;
	margin-left: 20px;
	height: 30px;
	line-height: 30px;
}

.province .checkbox-inline {
	padding-top: 0;
}

h3, h4, h5 {
	margin: 5px 0;
	font-weight: 600;
}

input[type=email], input[type=url], input[type=search], input[type=tel],
	input[type=color], input[type=text], input[type=password], input[type=datetime],
	input[type=datetime-local], input[type=date], input[type=month], input[type=time],
	input[type=week], input[type=number], textarea {
	border-radius: 0 !important;
	color: #858585;
	background-color: #FFF;
	border: 1px solid #D5D5D5;
	padding: 5px 4px 6px;
	font-size: 14px;
	font-family: inherit;
	-webkit-box-shadow: none !important;
	box-shadow: none !important;
	-webkit-transition-duration: .1s;
	transition-duration: .1s;
}

.spectable td, .spectable th {
	border: 1px solid #ccc;
	vertical-align: middle;
	text-align: center;
}

.spectable th {
	font-weight: bold;
}

.spectableinput {
	text-align: center;
}

.f {
	border-color: #b94a48;
	-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
	-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
	box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}

.table.table-bordered tr th, .table.table-bordered tr td {
	overflow: hidden;
	text-overflow: ellipsis;
}

select {
	padding: 3px 4px;
	height: 30px;
}
</style>
<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-sm-12">
				<div class="form-horizontal m-t">
					<div class="form-group">
						<ul class="nav nav-arrow-next nav-tabs" id="myTab">
							<li class="active"><a href="#tab_basic">基本信息</a></li>
							<li><a href="#tab_des">商品描述</a></li>
							<li><a href="#tab_postage">邮费设置</a></li>
							<li><a href="#tab_commission">佣金费设置</a></li>
							<li><a href="#tab_option">商品规格</a></li>
							<li><a href="#tab_areas">商品售卖区域</a></li>
						</ul>
					</div>
					<div class="tab-content" style="border: 0px;">
						<input type="hidden" id="id" th:value="${product.id}" />
						<div class="tab-pane active" id="tab_basic">
							<div class="form-group">
								<label class="col-sm-2 control-label">排序:</label>
								<div class="col-sm-6">
									<input id="displayorder" name="displayorder" maxlength="10"
										class="form-control" type="text"
										th:value="${product.displayorder}">
								</div>
								<label class="col-sm-2 control-label" style="text-align: left">数字越大，排名越靠前,限制小于2147483647</label>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label"><em class="gg-star" style="margin-right: 7px">*</em>商品名称:</label>
								<div class="col-sm-6">
									<input id="title" name="title" placeholder="必填：商品名称"
										class="form-control" type="text" maxlength="20"
										th:value="${product.title}">
								</div>
								<label class="col-sm-2 control-label"
									style="text-align: left; color: red;">*商品标题(20个汉字以内)</label>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">商品短标题:</label>
								<div class="col-sm-6">
									<input id="shortTitle" name="shortTitle" placeholder="商品短标题"
										class="form-control" type="text" maxlength="8"
										th:value="${product.shortTitle}">
								</div>
								<label class="col-sm-2 control-label" style="text-align: left">打印专用短标题(8个汉字以内)</label>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">商品编号:</label>
								<div class="col-sm-6">
									<input id="goodscode" name="goodscode" placeholder="商品编号"
										class="form-control" type="text"
										th:value="${product.goodscode}">
								</div>
								<label class="col-sm-2 control-label" style="text-align: left">识别商品的唯一编号</label>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">商品型号:</label>
								<div class="col-sm-6">
									<input id="specTitle" name="specTitle" class="form-control"
										type="text" th:value="${product.specTitle}">
								</div>
								<label class="col-sm-2 control-label" style="text-align: left">商品型号是商品售卖的规格描述，用于商品统计</label>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">商品生产日期:</label>
								<div class="col-sm-6">
									<input id="manudate" name="manudate" class="form-control"
										type="text" th:value="${product.manudate}">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">商品保质期:</label>
								<div class="col-sm-6">
									<input id="guarantday" name="guarantday" class="form-control"
										type="text" th:value="${product.guarantday}">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 商品分类： </label>
								<div class="col-sm-10">
									<div class="row row-fix tpl-category-container">
										<div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
											<select class="form-control tpl-category-parent" id="pcate"
												name="pcate" onchange="renderCategoryThird(this)">
												<option value="0">请选择顶级分类</option>
												<option th:selected="${product.pcate eq item.id}"
													th:each="item: ${category}" th:text="${item.name}"
													th:value="${item.id}"></option>
											</select>
										</div>
										<div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
											<select class="form-control tpl-category-child" id="ccate"
												name="ccate">
												<option value="0">请选择下级分类</option>
												<option th:selected="${product.ccate eq item.id}"
													th:each="item: ${product.ccategoryList}"
													th:text="${item.name}" th:value="${item.id}"></option>
											</select>
										</div>
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label">供应商:</label>
								<div class="col-sm-8">
									<select data-placeholder="" class="form-control chosen-select"
										id="supplierId" name="supplierId">
										<option th:value="0">请选择供应商</option>
										<option th:selected="${product.supplierId eq item.id}"
											th:each="item: ${supply}" th:text="${item.name}"
											th:value="${item.id}"></option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">单位:</label>
								<div class="col-sm-6">
									<input id="unit" name="unit" placeholder="单位如件/斤/袋"
										class="form-control" type="text" th:value="${product.unit}">
								</div>
								<label class="col-sm-2 control-label" style="text-align: left">单位如件/斤</label>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">商品属性:</label>
								<div class="col-sm-10">
									<!--<label for="iszhicai" class="checkbox-inline"> <input-->
										<!--type="checkbox" name="iszhicai" value="1"-->
										<!--th:checked="*{product.iszhicai}" id="iszhicai" /> 直采-->
									<!--</label> -->
									<label for="isnew" class="checkbox-inline"> <input
										type="checkbox" name="isnew" value="1"
										th:checked="*{product.isnew}" id="isnew" /> 新品
									</label> <label for="ishot" class="checkbox-inline"> <input
										type="checkbox" name="ishot" value="1"
										th:checked="*{product.ishot}" id="ishot" /> 爆款
									</label> <label for="ismao" class="checkbox-inline"> <input
										type="checkbox" name="ismao" value="1"
										th:checked="*{product.ismao}" id="ismao" /> 特卖
									</label>
									<!--<label for="isfanchang" class="checkbox-inline"> <input-->
										<!--type="checkbox" name="isfanchang" value="1"-->
										<!--th:checked="*{product.isfanchang}" id="isfanchang" /> 返场-->
									<!--</label>-->
									<!-- <label for="isgerida" class="checkbox-inline"> 
										<input type="checkbox" name="isgerida" value="1" th:checked="*{product.isgerida}" id="isgerida" /> 隔日达
									</label>  -->
									<!--<label for="ismiaosha" class="checkbox-inline"> <input-->
										<!--type="checkbox" name="ismiaosha" value="1"-->
										<!--th:checked="*{product.ismiaosha}" id="ismiaosha" /> 秒杀-->
									<!--</label> -->
									<!--<label for="islimited" class="checkbox-inline"> <input-->
										<!--type="checkbox" name="islimited" value="1"-->
										<!--th:checked="*{product.islimited}" id="islimited" /> 限量-->
									<!--</label> -->
									<!--<label for="isfashi" class="checkbox-inline"> <input-->
										<!--type="checkbox" name="isfashi" value="1"-->
										<!--th:checked="*{product.isfashi}" id="isfashi" /> 假一罚十-->
									<!--</label> -->
									<!--<label for="iszhutihuakuang" class="checkbox-inline">-->
										<!--<input type="checkbox" name="iszhutihuakuang" value="1"-->
										<!--th:checked="*{product.iszhutihuakuang}" id="iszhutihuakuang" />-->
										<!--主题画框-->
									<!--</label> -->
									<!--<label for="isbig" class="checkbox-inline"> <input-->
										<!--type="checkbox" name="isbig" value="1"-->
										<!--th:checked="*{product.isbig}" id="isbig" /> 大件-->
									<!--</label> -->
									<!--<label for="isvip" class="checkbox-inline"> <input-->
										<!--type="checkbox" name="isvip" value="1"-->
										<!--th:checked="*{product.isvip}" id="isvip" /> vip-->
									<!--</label>-->
									<!--<label for="isTeamBuy" class="checkbox-inline"> <input-->
											<!--type="checkbox" name="isTeamBuy" value="1"-->
											<!--th:checked="*{product.isTeamBuy}" id="isTeamBuy" /> 门店采购-->
									<!--</label>-->
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label">自定义属性:</label>
								<div class="col-sm-6">
									<input id="selfvalue" name="selfvalue"
										placeholder="如：年末促销,清仓处理" class="form-control" type="text"
										th:value="${product.selfvalue}">
								</div>
								<label class="col-sm-2 control-label" style="text-align: left">自定义添加商品属性，多个用','隔开。如：年末促销,清仓处理</label>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 限卖时间： </label>
								<div class="col-sm-10">
									<div class="col-sm-4 col-xs-6">
										<!-- <input type="text" name="timestart" id="timestart"
											value="" placeholder="请选择日期时间"
											onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
											readonly="readonly" class="datetimepicker form-control"
											style="padding-left: 12px;" /> -->
										<input type="text" name="timestart" id="timestart"
											placeholder="请选择日期时间" readonly="readonly"
											class="layui-input form-control" style="padding-left: 12px;">
									</div>
									<div class="col-sm-4 col-xs-6">
										<input type="text" name="timeend" value="" id="timeend"
											placeholder="请选择日期时间" readonly="readonly"
											class="layui-input form-control" style="padding-left: 12px;" />
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> <em class="gg-star" style="margin-right: 7px">*</em>商品图片： </label>
								<div class="col-sm-10">
									<div class="col-sm-6">
										<div class="input-group ">
											<input type="text" name="thumb" id="thumb"
												class="form-control" autocomplete="off"
												th:value="${product.thumb}"> <span
												class="input-group-btn">
												<button class="btn btn-sm btn-default"
													style="padding: 7px 10px" type="button"
													onclick="onSelectImgBtnClick('thumb','thumbImg')">选择图片</button>
											</span>
										</div>
										<div class="input-group " style="margin-top: .5em;">
											<img th:src="@{${product.thumb}}" id="thumbImg"
												style="width: 30%" />
										</div>
									</div>
									<span class="lbl col-xs-12 col-sm-6"> <span
										style="color: red;">*商城首页显示的第一张图片</span></span>
								</div>
							</div>


							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 商品正方形图片： </label>
								<div class="col-sm-10">
									<div class="col-sm-6">
										<div class="input-group ">
											<input type="text" name="thumbSquare" id="thumbSquare"
												class="form-control" autocomplete="off"
												th:value="${product.thumbSquare}"> <span
												class="input-group-btn">
												<button class="btn btn-sm btn-default"
													style="padding: 7px 10px" type="button"
													onclick="onSelectImgBtnClick('thumbSquare','thumbSquareImg');">选择图片</button>
											</span>
										</div>
										<div class="input-group " style="margin-top: .5em;">
											<img th:src="@{${product.thumbSquare}}" id="thumbSquareImg"
												style="width: 30%" />
										</div>
									</div>
									<span class="lbl col-xs-12 col-sm-6"><span class="red"></span>如不上传此图默认其他图片第一张图片作为正方形图片</span>
								</div>
							</div>


							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1">使用视频： </label>
								<div class="col-sm-10">
									<div class="col-sm-6">
										<div class="input-group">
											<input type="text" name="videourl" id="videourl"
												class="form-control" autocomplete="off"
												th:value="${product.videourl}"> <span
												class="input-group-btn">
												<button class="btn btn-sm btn-default"
													style="padding: 7px 10px"
													onclick="onSelectVideoBtnClick('videourl','videourl1');">选择媒体文件</button>
											</span>
										</div>
									</div>
									<span class="lbl col-xs-12 col-sm-6"><span class="red"></span>优先显示视频，使用视频后，其他图片的第一张图传缩略图，比列应该要和视频一样。</span>
								</div>
							</div>

							<div class="form-group">
								<div class="col-sm-8">
									<label class="col-sm-5 control-label"></label> <img
										class="img-responsive" id="categoryAddthumbImg" src=""
										style="max-width: 30%">
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1">其他图片:</label>
								<div class="col-sm-10">
									<div class="col-sm-6">
										<div class="input-group ">
											<input type="text" name="thumbUrl" id="thumbUrl"
												th:value="${product.thumbUrl}" class="form-control"
												autocomplete="off" placeholder="批量上传图片"> <span
												class="input-group-btn">
												<button class="btn btn-sm btn-default"
													style="padding: 7px 10px" type="button"
													onclick="selectImgs('thumbUrl');">选择图片</button>
											</span>
										</div>
										<div class="input-group " style="margin-top: .5em;">
											<img src="" id="thumbUrlImg" />
										</div>
									</div>
									<span class="lbl col-xs-12 col-sm-6"><span class="red"></span>如不上传此图默认其他图片第一张图片作为正方形图片</span>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 商品价格： </label>
								<div class="col-sm-6">
									<div class="input-group form-group">
										<span class="input-group-addon">建议零售价</span> <input type="text"
											name="suggestsaleprice" id="suggestsaleprice"
											class="form-control" th:value="${product.suggestsaleprice}" />
										<span class="input-group-addon">元 </span>
									</div>
									<div class="input-group form-group">
										<em class="gg-star">*</em><span class="input-group-addon">现价</span> <input type="text"
											name="marketprice" id="marketprice" class="form-control"
											th:value="${product.marketprice}" /> <span
											class="input-group-addon">元 </span>
									</div>

									<div class="input-group form-group">
										<em class="gg-star">*</em><span class="input-group-addon">原价</span> <input type="text"
											name="productprice" id="productprice" class="form-control"
											th:value="${product.productprice}" /> <span
											class="input-group-addon">元</span>
									</div>
									<div class="input-group form-group">
										<em class="gg-star">*</em><span class="input-group-addon">成本价</span>
										<input type="text" name="costprice" id="costprice" 
												class="form-control" th:value="${product.costprice}" />
										<span class="input-group-addon">元</span>
									</div>
									<div class='help-block'>
										<span style="color: red;">*现价：商品当前的销售价格，</span> <span
											style="color: red;">原价：商品最初的价格，</span>
										<span style="color: red;">成本价(非必填项)：商品的成本价格</span>
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> <em class="gg-star" style="margin-right: 7px">*</em>重量： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" name="weight" id="weight"
											class="form-control" th:value="${product.weight}" /> <span
											class="input-group-addon">克</span>
									</div>
									<div class='help-block'>商品重量设置空或0，则为包邮，如启用多规格，多规格内也需进行设置</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> <em class="gg-star" style="margin-right: 7px">*</em>库存： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" name="total" id="total" readonly="readonly"
											class="form-control" th:value="${product.total}" /> <span
											class="input-group-addon">件</span>
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 单次购买量： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" name="maxbuy" id="maxbuy"
											class="form-control" th:value="${product.maxbuy}" /> <span
											class="input-group-addon">件</span>
									</div>
									<span class="help-block">默认为0，表示不限制，用户单次购买此商品数量限制</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 用户最多购买量： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" id="usermaxbuy" name="usermaxbuy"
											class="form-control" th:value="${product.usermaxbuy}" /> <span
											class="input-group-addon">件</span>
									</div>
									<span class="help-block">默认为0，表示不限制，用户购买过的此商品数量限制</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									   for="form-field-1"> 门店最低购买量： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" id="startLimit" name="startLimit"
											   class="form-control" th:value="${product.startLimit}" /> <span
											class="input-group-addon">件</span>
									</div>
									<span class="help-block">默认为0，表示不限制，门店购买此商品数量最低限制</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 已出售数： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" name="sales" id="sales"
											class="form-control" th:value="${product.sales}" /> <span
											class="input-group-addon">件</span>
									</div>
									<span class="help-block">物品虚拟出售数，会员下单此数据就增加, 无论是否支付</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 已关注数： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" name="viewcount" id="viewcount"
											class="form-control" th:value="${product.viewcount}" /> <span
											class="input-group-addon">件</span>
									</div>
									<span class="help-block">物品虚拟关注数，会员查看商品详细此数据就增加, 无论是否支付</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 赠送积分： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" name="credit" id="credit"
											class="form-control" th:value="${product.credit}" /> <span
											class="input-group-addon">分</span>
									</div>
									<p class="help-block">会员购物赠送的积分,
										如果不填写或填写0，则默认为不赠送积分，如果带%则为按成交价格的比例计算积分</p>
									<p class="help-block">如: 购买2件，设置10 积分, 不管成交价格是多少，
										则购买后获得20积分</p>
									<p class="help-block">如: 购买2件，设置10%积分, 成交价格2 * 200= 400，
										则购买后获得 40 积分（400*10%）</p>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 是否上架： </label>
								<div class="col-sm-10" style="padding-top: 5px;">
									<label for="isshow1" class="radio-inline"> <input
										type="radio" onclick='radioIsChecked()' name="status"
										value="1" id="isshow1" /> 是
									</label> &nbsp;&nbsp;&nbsp; <label for="isshow2" class="radio-inline">
										<input type="radio" onclick='radioIsChecked()' name="status"
										value="0" id="isshow2" checked="checked" /> 否
									</label> &nbsp;&nbsp;&nbsp; <label for="isshow3" class="radio-inline"><input
										type="radio" onclick='radioIsChecked()' name="status"
										value="2" id="isshow3" /> 按时间范围上架 </label> <span class="help-block"></span>
								</div>
							</div>

							<div class="form-group" id='shangjiadiv' style='display: none;'>
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 上架时间范围： </label>
								<div class="col-sm-10">
									<div class="col-sm-4 col-xs-6">
										<input type="text" name="upStartTime" id="upStartTime"
											placeholder="请选择日期时间"
											onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
											readonly="readonly" class="datetimepicker form-control"
											style="padding-left: 12px;" />
									</div>
									<div class="col-sm-4 col-xs-6">
										<input type="text" name="upEndTime" id="upEndTime"
											placeholder="请选择日期时间"
											onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
											readonly="readonly" class="datetimepicker form-control"
											style="padding-left: 12px;" />
									</div>
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 是否开启公益金： </label>
								<div class="col-sm-10" style="padding-top: 5px;">
									<label for="gongyiisshow0" class="radio-inline"> <input
										type="radio" onclick='gongyiIsChecked()' name="isgongyi"
										value="0" id="gongyiisshow0" checked /> 不开启
									</label> &nbsp;&nbsp;&nbsp; <label for="gongyiisshow1"
										class="radio-inline"> <input type="radio"
										onclick='gongyiIsChecked()' name="isgongyi" value="1"
										id="gongyiisshow1" /> 开启
									</label> <span class="help-block"></span>
								</div>
							</div>

							<div class="form-group" id='gongyidiv' style='display: none'>
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 捐助公益金： </label>
								<div class="col-sm-6">
									<div class="input-group">
										<input type="text" name="gongyiprice" id="gongyiprice"
											class="form-control" th:value="${product.gongyiprice}" /> <span
											class="input-group-addon">元</span>
									</div>
									<span class="help-block">公益金在系统自动收获时添加添加到公益资金池</span>
								</div>
							</div>


							<div class="form-group" id='' style=''>
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 是否显示供应商： </label>
								<div class="col-sm-6">
									<label for="showsupply1" class="radio-inline"> <input
										type="radio" name="showsupply" value="1" id="showsupply1" />
										显示
									</label> &nbsp;&nbsp;&nbsp; <label for="showsupply2"
										class="radio-inline"> <input type="radio"
										name="showsupply" value="2" id="showsupply2" checked="checked" />
										不显示
									</label> <span class="help-block">默认显示供应商，前端页面标识商品供应商</span>
								</div>
							</div>

							<div class="form-group" style=''>
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 是否可以取消： </label>
								<div class="col-sm-6">
									<label for="uncancelable1" class="radio-inline"> <input
										type="radio" name="uncancelable" value="1" id="uncancelable1" />
										不能取消
									</label> &nbsp;&nbsp;&nbsp; <label for="uncancelable2"
										class="radio-inline"> <input type="radio"
										name="uncancelable" value="0" id="uncancelable2"
										checked="checked" /> 可以取消
									</label> <span class="help-block">生成订单时将不能取消不能退款，默认可以取消</span>
								</div>
							</div>
						</div>


						<!-- 商品描述部分 开始 -->
						<div class="tab-pane" id="tab_des">
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1">商品详情</label>
								<div class="col-sm-10">
									<textarea id="content" name="content" style="height: 200px;"
										th:text="${product.description}"></textarea>
								</div>

							</div>

							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1">商品描述</label>
								<div class="col-sm-10">
									<textarea id="proddes" name="proddes"
										style="height: 200px; width: 500px"
										th:text="${product.proddes}"></textarea>
								</div>
							</div>
						</div>
						<!-- 商品描述部分 结束-->

						<!-- 邮费设置部分 开始 -->
						<div class="tab-pane" id="tab_postage">
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 提货时间： </label>
								<div class="col-sm-6">
									<input type="text" name="tihuoday" id="tihuoday"
										th:value="${product.tihuoday}" class="col-xs-10 col-sm-8">
									<div class="input-group-addon"
										style="width: 50px; height: 34px;">
										<span style="font-size: 18px;">分钟</span>
									</div>
									<span style="padding-left: 10px; line-height: 35px;">
										预计发货节点后多少分钟可到货，无则表示采用<a>系统设置</a>
									</span>
								</div>
							</div>
							<div class="space-4"></div>
							<input type="hidden" id="free_shipping" value="">
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 邮费设置： </label>
								<div class="col-sm-6">
									<label for="totalcnf1" class="radio-inline"> <input
										th:field="*{product.freeShipping}" type="radio"
										name="free_shipping" value="0" id="totalcnf1"
										checked="checked" /> 包邮
									</label> &nbsp;&nbsp;&nbsp; <label for="totalcnf2" class="radio-inline">
										<input th:field="*{product.freeShipping}" type="radio"
										name="free_shipping" value="1" id="totalcnf2" />独立邮费
									</label> <label for="totalcnf2" style="padding-left: 10px;"> <input
										type="text" name="sendprice" id="sendprice"
										style="float: left; width: 100px;" value="" />&nbsp;&nbsp;
									</label>&nbsp;&nbsp;&nbsp; <label for="totalcnf3" class="radio-inline">
										<input th:field="*{product.freeShipping}" type="radio"
										name="free_shipping" value="2" id="totalcnf3" /> 邮费模板
									</label> <label for="totalcnf3"
										style="padding-left: 10px; width: 300px;"> <select
										name="dispatchid" id='dispatchid' class="form-control">
											<option value="0">请选择邮费模板</option>
											<option th:selected="${product.dispatchid eq item.id}"
												th:each="item: ${dispatch}" th:text="${item.dispatchname}"
												th:value="${item.id}"></option>
									</select>
									</label>
								</div>
							</div>
						</div>
						<!-- 邮费设置部分 结束 -->



						<!-- 佣金费设置部分 开始 -->
						<div class="tab-pane" id="tab_commission">
							&nbsp;
							<!--<div class="form-group">-->
								<!--<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否开启门店佣金:</label>-->
								<!--<div class="col-sm-9 col-xs-12">-->
									<!--<label class="checkbox-inline"> <input-->
										<!--th:checked="${product.isFxCommission}" type="checkbox"-->
										<!--id="is_fx_commission" value="0" name="is_fx_commission" />开启门店佣金-->
									<!--</label> <span class="help-block">关闭后，将不给门店返佣。佣金设置的金额和比例都为0.00表示采用-->
										<!--<a>系统设置</a>的提成比例计算佣金-->
									<!--</span>-->
								<!--</div>-->
							<!--</div>-->


							<!--<div class="form-group">-->
								<!--<label class="col-sm-2 control-label no-padding-right"-->
									<!--for="form-field-1"> 佣金设置： </label>-->
								<!--<div class="col-sm-6">-->
									<!--<label for="totalcnf2" class="radio-inline">门店佣金设置&nbsp;&nbsp;&nbsp;</label>-->
									<!--<label for="totalcnf2" style="padding-left: 10px;"> <input-->
										<!--type="text" name="headcommission" id="headcommission"-->
										<!--style="float: left; width: 100px;" disabled-->
										<!--th:value="${product.headcommission}" />&nbsp;-->
									<!--</label> <label class="radio-inline"-->
										<!--style="padding: 9px 0px 0px 0px; width: 40px;"> <select-->
										<!--th:field="*{product.headtype}" name="headtype" id="headtype"-->
										<!--style="height: 34px;"onchange="changeVal()">-->
											<!--<option value="0">元</option>-->
											<!--<option value="1">%</option>-->
									<!--</select>-->
									<!--</label>-->
								<!--</div>-->
							<!--</div>-->


							<!--<div class="form-group">-->
								<!--<label class="col-sm-2 control-label no-padding-right"-->
									<!--for="form-field-1"> </label>-->
								<!--<div class="col-sm-6">-->
									<!--<label for="totalcnf2" class="radio-inline">门店推荐人佣金 </label> <label-->
										<!--for="totalcnf2" style="padding-left: 10px;"> <input-->
										<!--type="text" name="superiorcommission" id="superiorcommission"-->
										<!--style="float: left; width: 100px;" disabled-->
										<!--th:value="${product.superiorcommission}" />&nbsp;-->
									<!--</label> <label class="radio-inline"-->
										<!--style="padding: 9px 0px 0px 0px; width: 40px;"> <select-->
										<!--th:field="*{product.superiortype}" name="superiortype"-->
										<!--style="height: 34px;"onchange="changeValue()">-->
											<!--<option value="0">元</option>-->
											<!--<option value="1">%</option>-->
									<!--</select>-->
									<!--</label>-->
								<!--</div>-->
							<!--</div>-->
						<!--</div>-->
						<!-- 佣金费设置部分 结束 -->

						<!-- 商品规格部分  开始 -->
						<div class="tab-pane" id="tab_option">
							<div class="form-group">
								<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否启用商品规格</label>
								<div class="col-sm-9 col-xs-12">

									<label class="checkbox-inline"> <input type="checkbox"
										id="hasoption" value="1" name="hasoption" />启用商品规格
									</label> <label class="checkbox-inline" id='second_speccid'
										style="display: none"> <input type="checkbox"
										id="second_spec" value="1" name="second_spec" />启用商品多规格同时下单
									</label> <span class="help-block">启用商品规格后，商品的价格及库存以商品规格为准,库存设置为0则不显示,-1为不限制</span>
								</div>
							</div>

							<div id='tboption' style="display: none">
								<div class="alert alert-info">
									<!-- 1. 拖动规格可调整规格显示顺序, 更改规格及规格项后请点击下方的【刷新规格项目表】来更新数据。<br/> -->
									<!-- 2.  -->
									每一种规格代表不同型号，例如颜色为一种规格，尺寸为一种规格，如果设置多规格，手机用户必须每一种规格都选择一个规格项，才能添加购物车或购买。
								</div>
								<div id='specs'></div>

								<table class="table">
									<tr>
										<td>
											<h4>
												<a href="javascript:;" class='btn btn-primary' id='add-spec'
													onclick="addSpec()"
													style="margin-top: 10px; margin-bottom: 10px;" title="添加规格">
													<i class='fa fa-plus'></i> 添加规格
												</a> <a onclick="calc()" title="刷新规格项目表" class="btn btn-primary">
													<i class="fa fa-refresh"></i> 刷新规格项目表
												</a>
											</h4>
										</td>
									</tr>
								</table>

								<div class="panel-body table-responsive" id="options"
									style="padding: 0;"></div>
							</div>
						</div>
						<!-- 商品规格部分  结束 -->

						<!-- 商品售卖区域部分  开始 -->
						<div class="tab-pane" id="tab_areas">
							<div class="form-group">
								<label class="col-xs-12 col-sm-3 col-md-2 control-label"
									for="form-field-1"> 商品售卖区域</label>
								<div class="col-sm-9 col-xs-12">
									<div id="areas" class="form-control-static">长沙市;株洲市;湘潭市;岳阳市;</div>
									<a href="javascript:;" class="btn btn-default"
										onclick="selectAreas()">选择地区</a> <input type="hidden"
										id="selectedareas" name="areas" th:value="${product.areas}" />
								</div>
							</div>

							<!-- <div class="form-group">
								<label class="col-sm-2 control-label no-padding-right"
									for="form-field-1"> 设置门店白名单: </label>
								<div class="col-sm-4">
									<div class="tags" style="width: 100%; min-height: 34px;">
									</div>
									<input type="hidden" name="tname_white_list"
										id="tname_white_list" value=""> 
									<input type="hidden" name="tid_white_list" id="tid_white_list" value="">
								</div>
								<div class="col-sm-1">
									点击添加模态框（Modal）
									<button class="btn btn-sm btn-danger" type="button"
										data-toggle="modal" data-target="#modal-teams"
										onclick="headlist(0)">添加门店
									</button>
								</div>
							</div> -->

							<div id="modal-areas" class="modal fade" tabindex="-1">
								<div class="modal-dialog" style='width: 920px;'>
									<div class="modal-content">
										<div class="modal-header">
											<button aria-hidden="true" data-dismiss="modal" class="close"
												type="button">×</button>
											<h3>选择区域</h3>
										</div>
										<div class="modal-body" id="areas-modal-body"
											style='height: 280px;'>
											<div class='province'>
												<label class='checkbox-inline' style='margin-left: 20px;'>
													<input type='checkbox' class='cityall'
													style='margin-top: 12px;' /> <span class="citycount"
													style='color: #ff6600'></span>
												</label>
											</div>
										</div>
										<div class="modal-footer">
											<a id='btnSubmitArea' class="btn btn-success"
												data-dismiss="modal" aria-hidden="true">确定</a> <a
												class="btn btn-default" data-dismiss="modal"
												aria-hidden="true">关闭</a>
										</div>
									</div>
								</div>
							</div>


							<div class="modal fade" id="modal-teams" tabindex="-1">
								<div class="modal-dialog">
									<div class="modal-content">
										<div class="modal-header">
											<button type="button" class="close" data-dismiss="modal"
												aria-hidden="true">×</button>
											<h4 class="modal-title">选择门店</h4>
										</div>
										<div class="modal-body">
											<div class="row">
												<div class="col-xs-12">
													<div class="form-group">
														<label class="col-sm-2 control-label no-padding-right"
															for="form-field-1"> 门店名称： </label>
														<div class="col-sm-10">
															<input type="text" id="select_team_key"
																placeholder="输入门店名称/门店姓名/手机"
																class="col-xs-10 col-sm-5 admin_sea"> <a
																class="btn btn-xs btm-input btn-purple"
																onclick="headlist(0)"> <span
																class="ace-icon fa fa-search icon-on-right bigger-110"></span>
																搜索
															</a>
														</div>
													</div>
													<div class="space-4"></div>
												</div>
											</div>
											<div class="row">
												<div class="col-xs-12">
													<div>
														<input name="p" id="p" value="1" type="hidden">
														<div class="table-responsive">
															<table
																class="table table-striped table-bordered table-hover">
																<thead>
																	<tr>
																		<th class="hidden-xs">ID</th>
																		<th>门店</th>
																		<th>门店名称</th>
																		<th style="border-right: #CCC solid 1px;">操作</th>
																	</tr>
																</thead>

																<tbody id="ajax-data1"></tbody>
															</table>
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- 商品售卖区域部分  结束 -->

					</div>
					<div class="form-group text-center">
						<div class="col-sm-8 col-sm-offset-2">
							<button class="btn btn-primary" onclick="updateProduct()">
								<i class="fa fa-check"></i>提交
							</button>
							<!-- <div class="btn btn-danger" onclick="closeDow()">
								<i class="fa fa-remove"></i> 关闭
							</div> -->
						</div>
					</div>
				</div>
			</div>
		</div>

	</div>
	<div th:include="centre/manage/include::footer"></div>
	<script type="text/javascript" src="/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript" src="/js/ueditor/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="/js/ueditor/custom.js?v=2"></script>
	<script type="text/javascript" src="/js/appjs/product/AreaData.js"></script>
	<script type="text/javascript" src="/public/ace/js/ace-extra.js"></script>
	<script type="text/javascript" src="/js/plugins/layui/layui.js"></script>
    <script src="/js/jquery-select/jquery.searchableSelect.js"></script>
	<script type="text/javascript">
	$(function(){
		/* $('#pcate').searchableSelect();
		$('#ccate ').searchableSelect(); */
		$('#supplierId').searchableSelect();
	});
		function closeDow() {
			var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
			parent.layer.close(index);
		}

		layui.use('laydate', function() {
			var laydate = layui.laydate;
			laydate.render({
				elem : '#timestart',
				type : 'datetime'
			});

			laydate.render({
				elem : '#timeend',
				type : 'datetime'
			});
			laydate.render({
				elem : '#upStartTime',
				type : 'datetime'
			});

			laydate.render({
				elem : '#upEndTime',
				type : 'datetime'
			});
		 
		})

			function changeValue() {
		   var	suggestsaleprice =  $("#suggestsaleprice").val();
		   var	superiorcommission =  $("#superiorcommission").val();
		   var  superiortype = $("#superiortype option:selected").val();
		  if(superiortype==1){
			  $("#superiorcommission").val(suggestsaleprice * (superiorcommission/100));
			  $("#superiortype option:first").prop("selected", 'selected');
		  }
		}
		
		function changeVal() {
			   var	suggestsaleprice =  $("#suggestsaleprice").val();
			   var	headcommission =  $("#headcommission").val();
			   var  headtype = $("#headtype option:selected").val();
			  if(headtype==1){
				  $("#headcommission").val(suggestsaleprice * (headcommission/100));
				  $("#headtype option:first").prop("selected", 'selected');
			  }
			}
		
		var specCountNum = 1;
		$(function() {
			var id = $('#id').val();
			$
					.ajax({
						url : '/product/data/detail?id=' + id,
						contentType : "application/json",
						dataType : "json",
						type : 'GET',
						success : function(result) {
							$('input[name="timestart"]').val(result.timestart);
							$('input[name="timeend"]').val(result.timeend);
							$('input[name="upStartTime"]').val(
									result.upStartTime);
							$('input[name="upEndTime"]').val(result.upEndTime);
							$('input[name="manudate"]').val(result.manudate);
							$("#areas").html(result.areas);

							$(
									":radio[name='status'][value='"
											+ result.status + "']").prop(
									"checked", "checked");
							if (result.status == 2) {
								$('#shangjiadiv').css('display', '');
							}
							$(
									":radio[name='isgongyi'][value='"
											+ result.isgongyi + "']").prop(
									"checked", "checked");
							if (result.isgongyi == 1) {
								$('#gongyidiv').css('display', '');
							}
							$(
									":radio[name='showsupply'][value='"
											+ result.showsupply + "']").prop(
									"checked", "checked");
							$(
									":radio[name='uncancelable'][value='"
											+ result.uncancelable + "']").prop(
									"checked", "checked");

							show_type(result.freeShipping);
							if (result.freeShipping == 1) {
								$("#sendprice").val(result.sendprice);
							}

							if (result.hasoptionsbuy == 1) {
								$('#second_speccid').css('display', '');
								$('input[name="hasoption"]').attr('checked',
										true);
								$('input[name="second_spec"]').attr('checked',
										true);
							} else if (result.hasoption == 1
									&& result.hasoptionsbuy == 0) {
								$('#second_speccid').css('display', '');
								$('input[name="hasoption"]').attr('checked',
										true);
							}
							if (result.specList != null
									&& result.specList.length > 0) {
								var html = '';
								for (var i = 0; i < result.specList.length; i++) {
									html += '<div class="panel panel-default spec_item" id="spec_dcx' + specCountNum +'">'
											+ '<div class="panel-body"> '
											+ '<input type="hidden" class="form-control spec_id" value="'+ result.specList[i].id +'" /> '
											+ '<div class="form-group"> '
											+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label">规格名 </label> '
											+ '<div class="col-sm-9 col-xs-12"> '
											+ '<input name="spec_title[dcx'
											+ specCountNum
											+ ']" type="text" class="form-control spec_title" value="'
											+ result.specList[i].title
											+ '" placeholder="(比如: 颜色)" /> '
											+ '</div> ' + '</div> ';
									if (result.hasoptionsbuy == 1) {
										html += '<div name="listspecdel" style=""> '
												+ '<div class="form-group"> '
												+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> '
												+ '<div class="col-sm-9 col-xs-12"> '
												+ '<a href="javascript:void(0);" class="btn btn-danger" onclick="removeSpec(\'dcx'
												+ specCountNum
												+ '\')"> <i class="fa fa-plus"></i> 删除规格</a> '
												+ '</div> '
												+ '</div> '
												+ '</div> ';
									} else {
										html += '<div name="listspec" style=""> '
												+ '<div class="form-group"> '
												+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label">规格项</label> '
												+ '<div class="col-sm-9 col-xs-12"> '
												+ '<div id="spec_item_dcx'+specCountNum+'" class="spec_item_items">';
										if (result.specList[i].specItemList != null
												&& result.specList[i].specItemList.length > 0) {
											for (var j = 0; j < result.specList[i].specItemList.length; j++) {
												html += '<div class="spec_item_item" style="float:left;margin:0 5px 10px 0;width:250px;">'
														+ '<div class="input-group" style="margin:10px 0;">'
														+ '<span class="input-group-addon"> <label class="checkbox-inline" style="margin-top:-20px;"><input type="checkbox" checked="" value="1" onclick="showItem(this)" /></label></span> '
														+ '<input data-index='+result.specList[i].specItemList[j].id+' type="text" class="form-control spec_item_title error" value="'+result.specList[i].specItemList[j].title+'" /> '
														+ '<span class="input-group-addon"><a href="javascript:;" onclick="removeSpecItem(this)" title="删除"> <i class="fa fa-times"></i></a></span> '
														+ '</div>'
														+ '<div class="input-group "> '
														+ '<input type="text" value="'+result.specList[i].specItemList[j].thumb+'" class="form-control thumb" autocomplete="off" id="specItemThumb_'+result.specList[i].specItemList[j].id+'"/> '
														+ '<span class="input-group-btn"> <button class="btn btn-sm btn-default" type="button" onclick="onSelectImgBtnClick(\'specItemThumb_'
														+ result.specList[i].specItemList[j].id
														+ '\',\'dd\');">选择图片</button> </span> '
														+ '</div> '
														+ '<div class="input-group " style="margin-top:.5em;"> '
														+
														//'<em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em> '+
														'</div></div>'
											}
										}
										html += '</div> '
												+ '</div> '
												+ '</div> '
												+ '<div class="form-group"> '
												+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> '
												+ '<div class="col-sm-9 col-xs-12"> '
												+ '<span> <a id="add-specitem-dcx'
												+ specCountNum
												+ '" specid="dcx'
												+ specCountNum
												+ '" class="btn btn-info add-specitem" onclick="addSpecItem(\'dcx'
												+ specCountNum
												+ '\')"> '
												+ '<i class="fa fa-plus"></i> 添加规格项</a></span> '
												+ '<a class="btn btn-danger" onclick="removeSpec(\'dcx'
												+ specCountNum
												+ '\')"> <i class="fa fa-plus"></i> 删除规格</a> '
												+ '</div> ' + '</div> '
												+ '</div> ';

									}
									html += '</div></div>';
									specCountNum++;
								}
								$('#specs').append(html);
								$('#tboption').css('display', 'block');
							}

							var skus = [];
							if (result.skuList.length > 0) {
								for (var i = 0; i < result.skuList.length; i++) {
									var sku = {
										id : result.skuList[i].id,
										title : result.skuList[i].title,
										costprice : result.skuList[i].costprice,
										headcommission : result.skuList[i].headcommission,
										headtype : result.skuList[i].headtype,
										marketprice : result.skuList[i].marketprice,
										productprice : result.skuList[i].productprice,
										stock : result.skuList[i].stock,
										superiorcommission : result.skuList[i].superiorcommission,
										superiortype : result.skuList[i].superiortype,
										weight : result.skuList[i].weight
									}
									skus.push(sku);
								}
								var len = skus.length;
								var h = new Array(len);
								if (result.hasoptionsbuy == 1) {
									var hh = '<input name="kw" type="hidden"  value="1"/>';

									for (var i = 0; i < len; i++) {
										var html = '<table class="table table-bordered table-condensed skuTable"><thead><tr class="active">';
										html += "<th style='width:80px;'></th>";
										html += '<th class="info" style="width:130px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">库存</div><div class="input-group"><input type="text" class="form-control option_stock_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
										html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">销售价格</div><div class="input-group"><input type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
										html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">市场价格</div><div class="input-group"><input type="text" class="form-control option_productprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
										html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">重量（克）</div><div class="input-group"><input type="text" class="form-control option_weight_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
										html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店佣金（元）</div><div class="input-group"><input type="text" class="form-control option_headcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_headcommission\');"></a></span></div></div></th>';
										html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店推荐人佣金（元）</div><div class="input-group"><input type="text" class="form-control option_superiorcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_superiorcommission\');"></a></span></div></div></th>';
										html += '</tr></thead>';
										hh += "<tr>";

										hh += "<td style='width:80px;'>"
												+ skus[i].title + "</td>";
										hh += '<td class="info"><input type="text" class="form-control option_stock" value="'
												+ (skus[i].stock) + '"/></td>';
										hh += '<input type="hidden" class="form-control option_id" value="' + skus[i].id + '"/>';
										/* hh += '<input type="hidden" class="form-control option_ids" value="' + skus[i].id + '"/>'; */
										hh += '<input type="hidden" class="form-control option_title" value="' + skus[i].title + '"/></td>';
										/* hh += '<input name="option_virtual_' + skus[i].id + '[]"type="hidden" class="form-control option_title option_title_' + skus[i].id + '" value="' + (val.virtual == 'undefined' ? '': val.virtual) + '"/></td>'; */
										hh += '</td>';
										hh += '<td class="success"><input name="option_marketprice_'
												+ skus[i].id
												+ '[]" type="text" class="form-control option_marketprice option_marketprice_'
												+ skus[i].id
												+ '" value="'
												+ (skus[i].marketprice)
												+ '"/></td>';
										hh += '<td class="warning"><input name="option_productprice_'
												+ skus[i].id
												+ '[]" type="text" class="form-control option_productprice option_productprice_'
												+ skus[i].id
												+ '" " value="'
												+ (skus[i].productprice)
												+ '"/></td>';
										hh += '<td class="info"><input name="option_weight_'
												+ skus[i].id
												+ '[]" type="text" class="form-control option_weight option_weight_'
												+ skus[i].id
												+ '" " value="'
												+ (skus[i].weight) + '"/></td>';
										//hh += '<td class="info"><input name="option_headcommission_' + skus[i].id  +'[]" type="text" class="form-control option_headcommission option_headcommission_' + skus[i].id  +'" " value="' +(val.headcommission=='undefined'?'':val.headcommission )+'"/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_superiorcommission\');"></a></span></td>';
										hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_headcommission_'
												+ skus[i].id
												+ '[]" type="text" class="form-control option_headcommission option_headcommission_'
												+ skus[i].id
												+ '" " value="'
												+ (skus[i].headcommission)
												+ '"/><span class="input-group-addon" style="padding:0px;"><select  name="option_headtype_' + skus[i].id + '[]" class="option_headtype option_headtype_' + skus[i].id + '"  style="border-style:solid; border-color:#FFF">';
										if (skus[i].headtype == 0) {
											hh += '<option value="0" selected>元</option><option value="1">%</option></select></span></div></div></td>';
										} else {
											hh += '<option value="0">元</option><option value="1" selected>%</option></select></span></div></div></td>';
										}
										hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_superiorcommission_'
												+ skus[i].id
												+ '[]" type="text" class="form-control option_superiorcommission option_superiorcommission_'
												+ skus[i].id
												+ '" " value="'
												+ (skus[i].superiorcommission)
												+ '"/><span class="input-group-addon" style="padding:0px;"><select name="option_superiortype_' + skus[i].id + '[]" class="option_superiortype option_superiortype_' + skus[i].id + '"  style="border-style:solid; border-color:#FFF">';
										if (sku[i].superiortype == 0) {
											hh += '<option value="0" selected>元</option><option value="1">%</option></select></span></div></div></td>';
										} else {
											hh += '<option value="0">元</option><option value="1" selected>%</option></select></span></div></div></td>';
										}
										hh += "</tr>";
									}
									html += hh;
									html += "</table>";
									$("#options").html(html);
								} else {
									var html = '<table class="table table-bordered table-condensed skuTable"><thead><tr class="active">';
									var specs = result.specList;
									var skuList = result.skuList;

									/* for (var i=0;i<result.skuList.length;i++) {
										var spec = {
									            id: result.skuList[i].id,
									            title: result.skuList[i].title
									    };
										var items = [];
										
										for (var j=0;j<result.skuList[i].length;i++){
											var item = {
									                id: result.skuList[j].id,
									                title: result.skuList[j].title
									        }
											items.push(item);
										}
										spec.items = items;
									    specs.push(spec);
									} */
									/* $(".spec_item").each(function(i) {
									    var _this = $(this);

									    var spec = {
									        id: _this.find(".spec_id").val(),
									        title: _this.find(".spec_title").val()
									    };

									    var items = [];
									    _this.find(".spec_item_item").each(function() {
									        var __this = $(this);
									        var item = {
									            id: __this.find(".spec_item_id").val(),
									            title: __this.find(".spec_item_title").val(),
									        }
									        items.push(item);
									    });
									    spec.items = items;
									    specs.push(spec);
									}); */

									specs
											.sort(function(x, y) {
												if (x.specItemList.length > y.specItemList.length) {
													return 1;
												}
												if (x.specItemList.length < y.specItemList.length) {
													return -1;
												}
											});

									var len = specs.length;
									var newlen = 1;
									var skuListLength = skuList.length;
									var h = new Array(len);
									var rowspans = new Array(len);
									for (var i = 0; i < len; i++) {
										html += "<th style='width:80px;'>"
												+ specs[i].title + "</th>";
										/* var itemlen = specs[i].specItemList.length;
										if (itemlen <= 0) {
										    itemlen = 1
										};
										newlen *= itemlen;
										h[i] = new Array(newlen);
										for (var j = 0; j < newlen; j++) {
										    h[i][j] = new Array();
										}
										var l = specs[i].specItemList.length;
										rowspans[i] = 1;
										for (j = i + 1; j < len; j++) {
										    rowspans[i] *= specs[j].specItemList.length;
										} */
									}

									html += '<th class="info" style="width:130px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">库存</div><div class="input-group"><input type="text" class="form-control option_stock_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
									html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">销售价格</div><div class="input-group"><input type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
									html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">市场价格</div><div class="input-group"><input type="text" class="form-control option_productprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
									html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">重量（克）</div><div class="input-group"><input type="text" class="form-control option_weight_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
									html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店佣金（元）</div><div class="input-group"><input type="text" class="form-control option_headcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_headcommission\');"></a></span></div></div></th>';
									html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店推荐人佣金（元）</div><div class="input-group"><input type="text" class="form-control option_superiorcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_superiorcommission\');"></a></span></div></div></th>';
									html += '</tr></thead>';

									/* for (var m = 0; m < len; m++) {
									    var k = 0,
									    kid = 0,
									    n = 0;
									    for (var j = 0; j < newlen; j++) {
									        var rowspan = rowspans[m];
									        if (j % rowspan == 0) {
									            h[m][j] = {
									                title: specs[m].items[kid].title,
									                virtual: specs[m].items[kid].virtual,
									                html: "<td rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
									                id: specs[m].items[kid].id
									            };
									        } else {
									            h[m][j] = {
									                title: specs[m].items[kid].title,
									                virtual: specs[m].items[kid].virtual,
									                html: "",
									                id: specs[m].items[kid].id
									            };
									        }
									        n++;
									        if (n == rowspan) {
									            kid++;
									            if (kid > specs[m].specItemList.length - 1) {
									                kid = 0;
									            }
									            n = 0;
									        }
									    }
									} */

									var hh = '';
									for (var i = 0; i < skuListLength; i++) {

										var skuTitle = skuList[i].title;
										hh += "<tr>";

										var skuTitleArray = skuTitle.split("+");
										for (var j = 0; j < skuTitleArray.length; j++) {
											hh += "<td>" + skuTitleArray[j]
													+ "</td>";
										}

										/* hh += "<tr>";
										var ids = [];
										var titles = [];
										var virtuals = [];
										for (var j = 0; j < len; j++) {
										    hh += "<td>" + skuList[j].title + "</td>";
										    ids.push(h[j][i].id);
										    titles.push(h[j][i].title);
										    virtuals.push(h[j][i].virtual);
										} */

										hh += '<td class="info"><input type="text" class="form-control option_stock" value="'
												+ (skuList[i].stock)
												+ '"/></td>';
										hh += '<input type="hidden" class="form-control option_id" value="' + skuList[i].id + '"/>';
										hh += '<input type="hidden" class="form-control option_ids" value="' + skuList[i].specs + '"/>';
										hh += '<input data-index="'+skuList[i].id+'" type="hidden" class="form-control option_title" value="' + skuList[i].title + '"/>';
										hh += '<input type="hidden" class="form-control option_specItemHiddenId" value="'+skuList[i].specs+ '"/></td>';
										/* hh += '</td>'; */
										hh += '<td class="success"><input type="text" class="form-control option_marketprice" value="' + skuList[i].marketprice + '"/></td>';
										hh += '<td class="warning"><input type="text" class="form-control option_productprice" value="' + skuList[i].productprice + '"/></td>';
										hh += '<td class="info"><input type="text" class="form-control option_weight"  value="' + skuList[i].weight + '"/></td>';
										hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input type="text" class="form-control option_headcommission" value="' + skuList[i].headcommission + '"/><span class="input-group-addon" style="padding:0px;"><select type="text" class="option_headtype"  style="border-style:solid; border-color:#FFF"  >'
										if (skuList[i].headtype == 0) {
											hh += '<option value="0" selected>元</option><option value="1">%</option></select></span></div></div></td>';
										} else {
											hh += '<option value="0">元</option><option value="1" selected>%</option></select></span></div></div></td>';
										}
										hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input type="text" class="form-control option_superiorcommission" value="' + skuList[i].superiorcommission + '"/><span class="input-group-addon" style="padding:0px;"><select type="text" class="option_superiortype"  style="border-style:solid; border-color:#FFF"  >';

										if (skuList[i].superiortype == 0) {
											hh += '<option value="0" selected>元</option><option value="1">%</option></select></span></div></div></td>';
										} else {
											hh += '<option value="0">元</option><option value="1" selected>%</option></select></span></div></div></td>';
										}

										hh += "</tr>";
									}
									html += hh;
									html += "</table>";
									$("#options").html(html);
								}
							}
						}
					})

			// tab切换
			$('#myTab a').click(function(e) {
				e.preventDefault();
				$('#myTab li').each(function() {
					$(this).removeClass('active')
				})
				$('.tab-content .tab-pane').each(function() {
					$(this).removeClass('active')
				})
				$(this).parent().addClass('active')
				id = $(this).attr('href')
				$(id).addClass('active');
			})

			// 是否开启门店佣金
			$("#is_fx_commission")
					.click(
							function() {
								var obj = $(this);
								if (obj.get(0).checked) {
									document
											.getElementById("superiorcommission").disabled = false;
									document.getElementById("headcommission").disabled = false;
								} else {
									document
											.getElementById("superiorcommission").disabled = true;
									document.getElementById("headcommission").disabled = true;
								}
							});

			// 启用商品多规格同时下单
			$("#second_spec").click(function() {
				var obj = $(this);
				var aDiv = document.getElementsByName('listspec');
				var aDivdel = document.getElementsByName('listspecdel');
				if (obj.get(0).checked) {
					$("#listspecdel").hide();
					for (var i = 0; i < aDiv.length; i++) {
						aDiv[i].style.display = "none";
						aDivdel[i].style.display = "";
					}
				} else {
					for (var i = 0; i < aDiv.length; i++) {
						aDiv[i].style.display = "";
						aDivdel[i].style.display = "none";
					}
				}
			});

			// 是否按时间范围上架
			radioIsChecked();
		})

		// 是否按时间范围上架
		function radioIsChecked() {
			if ($("#isshow3").is(':checked')) {
				$('#shangjiadiv').show();
			} else {
				$('#shangjiadiv').hide();
			}
		}

		function gongyiIsChecked() {
			if ($("#gongyiisshow1").is(':checked')) {
				$('#gongyidiv').show();
			} else {
				$('#gongyidiv').hide();
			}
		}

		function selectAreas() {
			clearSelects();
			var old_citys = $('#areas').html().split(';');
			$('.city').each(
					function() {
						var parentcheck = false;
						for ( var i in old_citys) {
							if (old_citys[i] == $(this).attr('city')) {
								parentcheck = true;
								$(this).get(0).checked = true;
								break;
							}
						}
						if (parentcheck) {
							$(this).parent().parent().parent().parent().find(
									'.cityall').get(0).checked = true;
						}
					});

			$("#modal-areas").modal();
			var citystrs = '';
			$('#btnSubmitArea').unbind('click').click(function() {
				$('.city:checked').each(function() {
					citystrs += $(this).attr('city') + ";";
				});
				$('#areas').html(citystrs);
				$("#selectedareas").val(citystrs);
			})
		}

		function clearSelects() {
			$('.city').attr('checked', false).removeAttr('disabled');
			$('.cityall').attr('checked', false).removeAttr('disabled');
			$('.citycount').html('');
		}

		var yixuanXiaoqu = [];

		showYixuanXiaoqu();

		function headlist(page) {

			var title = $('#select_team_key').val();
			$.ajax({
				type : "post",
				url : "/admin/goods/select_team.html",
				data : {
					title : title,
					page : page
				},
				dataType : "json",
				success : function(data) {
					if (data.length > 0) {
						$('#ajax-data1').html(data);
					} else {
						$('#ajax-data1').html("没有门店");
					}
					$('#ajax-data1').html(data);

					match_already_select()
				}
			})
		}
		function match_already_select() {
			var mids = $('#tid_white_list').val()

			//	    		var goods_titles = $('#goods_titles').val()
			idsArr = mids.split(',');
			//	    		titlesArr = goods_titles.split(',');
			for (var i = 0; i < idsArr.length; i++) {
				$('.sel' + idsArr[i]).removeClass("fa-plus")
				$('.sel' + idsArr[i]).addClass("fa-check fa-check1")
			}
		}
		function addTeamWhiteList(id, title) {
			var isHas = false;
			for (var i = 0; i < yixuanXiaoqu.length; i++) {
				var item = yixuanXiaoqu[i];
				if (id == item.id) {
					isHas = true;
					yixuanXiaoqu.splice(i, 1);
				}
			}
			if (isHas) {
				$('.sel' + id).removeClass("fa-check fa-check1")
				$('.sel' + id).addClass("fa-plus")
			} else {
				yixuanXiaoqu.push({
					id : id,
					title : title
				});
				$('.sel' + id).removeClass("fa-plus")
				$('.sel' + id).addClass("fa-check fa-check1")
			}

			showYixuanXiaoqu();
		}
		function showYixuanXiaoqu() {
			var HTML = '';
			var ids = '';
			var names = '';
			for (var i = 0; i < yixuanXiaoqu.length; i++) {
				ids += yixuanXiaoqu[i].id + ',';
				names += yixuanXiaoqu[i].title + ',';
				var item = yixuanXiaoqu[i];
				HTML += '<span class="tag  yixuanxiaoqu-'+item.id+' ">'
						+ item.title
						+ '<button type="button" class="close"  onclick="delmid('
						+ item.id + ')" >×</button></span>';
			}
			ids = ids.substr(0, ids.length - 1);
			names = names.substr(0, names.length - 1);
			$('#tid_white_list').val(ids);
			$('#tname_white_list').val(names);
			$('.tags').html(HTML);
		}
		//移除已选区小区
		function delmid(id) {
			for (var j = 0; j < yixuanXiaoqu.length; j++) {
				var yitem = yixuanXiaoqu[j];
				if (yitem.id == id) {
					yixuanXiaoqu.splice(j, 1);
				}
			}
			showYixuanXiaoqu();
		}

		$(function() {
			//从js数据中获取地区
			var areasModalBody = '';
			for (var i = 0; i < provs_data.length; i++) {
				console.log(provs_data[i]);
				areasModalBody += "<div class='province'>";
				areasModalBody += "<label class='checkbox-inline' style='margin-left:20px;'>";
				areasModalBody += "<input type='checkbox' class='cityall' style='margin-top:12px;' />";
				areasModalBody += provs_data[i].text;
				areasModalBody += "<span class='citycount' style='color:#ff6600'></span>";
				areasModalBody += "</label>";

				//获取省级下的所有市
				if (citys_data[provs_data[i].value].length > 0) {
					areasModalBody += "<ul>";
					var citys = citys_data[provs_data[i].value];
					for (var j = 0; j < citys.length; j++) {
						//	alert(JSON.stringify(dists_data[citys[j].value]));

						areasModalBody += "<li>";
						areasModalBody += "<label class='checkbox-inline' >";
						areasModalBody += "<input type='checkbox' class='city' style='margin-top:8px;' city="+citys[j].text+" />";
						areasModalBody += citys[j].text;
						areasModalBody += "</label>";
						areasModalBody += "</li>";
					}
					areasModalBody += "</ul>";
				}

				areasModalBody += "</div>";
			}
			$("#areas-modal-body").html(areasModalBody);

			$('.province').mouseover(function() {
				$(this).find('ul').show();
			}).mouseout(function() {
				$(this).find('ul').hide();
			});

			$('.cityall').click(
					function() {
						var checked = $(this).get(0).checked;
						var citys = $(this).parent().parent().find('.city');
						citys.each(function() {
							$(this).get(0).checked = checked;
						});
						var count = 0;
						if (checked) {
							count = $(this).parent().parent().find(
									'.city:checked').length;
						}
						if (count > 0) {
							$(this).next().html("(" + count + ")");
						} else {
							$(this).next().html("");
						}
					});
			$('.city').click(
					function() {
						var checked = $(this).get(0).checked;
						var cityall = $(this).parent().parent().parent()
								.parent().find('.cityall');

						if (checked) {
							cityall.get(0).checked = true;
						}
						var count = cityall.parent().parent().find(
								'.city:checked').length;
						if (count > 0) {
							cityall.next().html("(" + count + ")");
						} else {
							cityall.next().html("");
						}
					});

			$('#btnSubmitArea').unbind('click').click(function() {
				$('.city:checked').each(function() {
					citystrs += $(this).attr('city') + ";";
				});
				$('.' + current + ' .cityshtml').html(citystrs);
				$('.' + current + ' .citys').val(citystrs);
			})

		});

		var ue = UE.getEditor('content');
		$('#content').data('editor', ue);
		$('#content').parents('form').submit(function() {
			if (ue.queryCommandState('source')) {
				ue.execCommand('source');
			}
		});
		UE.registerUI('uploadImage', function(editor, uiName) {
			return new UE.ui.Button({
				name : '上传图片',
				title : '上传图片',
				cssRules : 'background-position:-380px 0',
				onclick : function() {
					layer.open({
						id : 'selectImgs',
						type : 2,
						title : '批量选择图片',
						maxmin : true,
						shadeClose : false,
						area : [ '60%', '70%' ],
						content : '/platform/config/batchUploadImgUeditor' // iframe的url
					});
				}
			});
		});

		function renderCategoryThird(obj) {
			var index = obj.options[obj.selectedIndex].value;
			var html = "<option value='0'>请选择下级分类</option>";
			if (index == 0) {
				$("#ccate").html(html);
			} else {
				$.ajax({
					url : "/category/manage/getChildByPar",
					data : {
						"id" : index
					},
					dataType : "json",
					success : function(data) {
						for (var i = 0; i < data.length; i++) {
							html += '<option value="'+data[i].id+'">'
									+ data[i].name + '</option>';
						}
						$("#ccate").html(html);
					}
				})
			}
		}

		function show_type(flag) {
			if (flag == 0) {
				document.getElementById("sendprice").disabled = true;
				document.getElementById("dispatchid").disabled = true;

			} else if (flag == 1) {
				document.getElementById("dispatchid").disabled = true;
				document.getElementById("sendprice").disabled = false;
			} else if (flag == 2) {
				document.getElementById("sendprice").disabled = true;
				document.getElementById("dispatchid").disabled = false;
			}
		}
		$(function() {
			var x = document.getElementById("free_shipping").value;
			show_type(x);
			$(':radio[name=free_shipping]').click(function() {
				var val = $(this).val();
				show_type(val);
			})
		});

		$(function() {
			$("#hasoption").click(function() {
				var obj = $(this);
				if (obj.get(0).checked) {
					$("#tboption").show();
					$("#second_speccid").show();
				} else {
					$("#tboption").hide();
					$("#second_speccid").hide();
				}
			});
		})

		function addSpec() {
			second_spec = 0;
			var spec = document.getElementById("second_spec");
			if (spec.checked) {
				second_spec = 1;
			}

			var html = '<div class="panel panel-default spec_item" id="spec_dcx' + specCountNum +'">'
					+ '<div class="panel-body"> '
					+ '<input name="spec_id[]" type="hidden" class="form-control spec_id" value="" /> '
					+ // value="dcx'+ specCountNum +'"
					'<div class="form-group"> '
					+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label">规格名 </label> '
					+ '<div class="col-sm-9 col-xs-12"> '
					+ '<input type="text" class="form-control spec_title" value="" placeholder="(比如: 颜色)" /> '
					+ '</div> ' + '</div> ';

			var secondHtml = '';
			if (second_spec == 1) {
				secondHtml = '<div name="listspec" style="display:none"> '
						+ '<div class="form-group"> '
						+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label">规格项</label> '
						+ '<div class="col-sm-9 col-xs-12"> '
						+ '<div id="spec_item_dcx'+specCountNum+'" class="spec_item_items"></div> '
						+ '</div> '
						+ '</div> '
						+ '<div class="form-group"> '
						+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> '
						+ '<div class="col-sm-9 col-xs-12"> '
						+ '<span> <a id="add-specitem-dcx'
						+ specCountNum
						+ '" specid="dcx'
						+ specCountNum
						+ '" class="btn btn-info add-specitem" onclick="addSpecItem(\'dcx'
						+ specCountNum
						+ '\')"> '
						+ '<i class="fa fa-plus"></i> 添加规格项</a></span> '
						+ '<a class="btn btn-danger" onclick="removeSpec(\'dcx'
						+ specCountNum
						+ '\')"> <i class="fa fa-plus"></i> 删除规格</a> '
						+ '</div> '
						+ '</div> '
						+ '</div> '
						+ '<div name="listspecdel" style=""> '
						+ '<div class="form-group"> '
						+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> '
						+ '<div class="col-sm-9 col-xs-12"> '
						+ '<a href="javascript:void(0);" class="btn btn-danger" onclick="removeSpec(\'dcx'
						+ specCountNum
						+ '\')"> <i class="fa fa-plus"></i> 删除规格</a> '
						+ '</div> ' + '</div> ' + '</div> ';
			} else {
				secondHtml = '<div name="listspec" style=""> '
						+ '<div class="form-group"> '
						+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label">规格项</label> '
						+ '<div class="col-sm-9 col-xs-12"> '
						+ '<div id="spec_item_dcx'+specCountNum+'" class="spec_item_items"></div> '
						+ '</div> '
						+ '</div> '
						+ '<div class="form-group"> '
						+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> '
						+ '<div class="col-sm-9 col-xs-12"> '
						+ '<span> <a id="add-specitem-dcx'
						+ specCountNum
						+ '" specid="dcx'
						+ specCountNum
						+ '" class="btn btn-info add-specitem" onclick="addSpecItem(\'dcx'
						+ specCountNum
						+ '\')"> '
						+ '<i class="fa fa-plus"></i> 添加规格项</a></span> '
						+ '<a class="btn btn-danger" onclick="removeSpec(\'dcx'
						+ specCountNum
						+ '\')"> <i class="fa fa-plus"></i> 删除规格</a> '
						+ '</div> '
						+ '</div> '
						+ '</div> '
						+ '<div name="listspecdel" style="display:none"> '
						+ '<div class="form-group"> '
						+ '<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label> '
						+ '<div class="col-sm-9 col-xs-12"> '
						+ '<a href="javascript:void(0);" class="btn btn-danger" onclick="removeSpec(\'dcx'
						+ specCountNum
						+ '\')"> <i class="fa fa-plus"></i> 删除规格</a> '
						+ '</div> ' + '</div> ' + '</div> ';
			}
			html += secondHtml + '</div></div>';

			second_spec = 0;
			var spec = document.getElementById("second_spec");
			if (spec.checked) {
				second_spec = 1;
			}

			var len = $(".spec_item").length;

			$("#add-spec").html("正在处理...").attr("disabled", "true")
					.toggleClass("btn-primary");
			$("#add-spec").html('<i class="fa fa-plus"></i> 添加规格').removeAttr(
					"disabled").toggleClass("btn-primary");
			$('#specs').append(html);
			var len = $(".add-specitem").length - 1;
			$(".add-specitem:eq(" + len + ")").focus();
			optionchanged = true;

			specCountNum++;
		}

		function removeSpec(specid) {
			if (confirm('确认要删除此规格?')) {
				$("#spec_" + specid).remove();
				optionchanged = true;
			}
			specCountNum--;
		}

		function addSpecItem(specid) {
			var specItemHiddenId = new Date().getTime();
			var html = '<div class="spec_item_item" style="float:left;margin:0 5px 10px 0;width:250px;">'
					+ '<div class="input-group" style="margin:10px 0;">'
					+ '<span class="input-group-addon"> <label class="checkbox-inline" style="margin-top:-20px;"><input type="checkbox" checked="" value="1" onclick="showItem(this)" /></label></span> '
					+ '<input data-index="'+specItemHiddenId+'" type="text" class="form-control spec_item_title error" value="" /> '
					+ '<span class="input-group-addon"><a href="javascript:;" onclick="removeSpecItem(this)" title="删除"> <i class="fa fa-times"></i></a></span> '
					+ '</div>'
					+ '<div class="input-group "> '
					+ '<input type="text" value="" class="form-control thumb" autocomplete="off" id="specItemThumb_'+specItemHiddenId+'"/> '
					+ '<span class="input-group-btn"> <button class="btn btn-sm btn-default" type="button" onclick="onSelectImgBtnClick(\'specItemThumb_'
					+ specItemHiddenId
					+ '\',\'dd\');">选择图片</button> </span> '
					+ '</div> '
					+ '<div class="input-group " style="margin-top:.5em;"> ' +
					//'<em class="close" style="position:absolute; top: 0px; right: -14px;" title="删除这张图片" onclick="deleteImage(this)">×</em> '+
					'</div>';
			$("#add-specitem-" + specid).html("正在处理...").attr("disabled",
					"true");
			$("#add-specitem-" + specid).html(
					'<i class="fa fa-plus"></i> 添加规格项').removeAttr("disabled");
			$('#spec_item_' + specid).append(html);
			var len = $("#spec_" + specid + " .spec_item_title").length - 1;
			$("#spec_" + specid + " .spec_item_title:eq(" + len + ")").focus();
			optionchanged = true;
		}

		function removeSpecItem(obj) {
			$(obj).parent().parent().parent().remove();
		}

		/* if ($('.spec_item').length > 0) {
			var specs = [];
			var specItems = [];
			$(".spec_item").each(function(i) {
				var _this = $(this);
				var spec = {
		            title: _this.find(".spec_title").val(),
		        };
				specs.push(spec); // 设置规格
			})
		} */

		function calc() {
			var spec = document.getElementById("second_spec");
			if (spec.checked) {
				optionchanged = false;
				var specs = [];
				if ($('.spec_item').length <= 0) {
					$("#options").html('');
					return;
				}
				$(".spec_item").each(function(i) {
					var _this = $(this);
					//alert(_this.find(".spec_title").val());
					var spec = {
						id : _this.find(".spec_id").val(),
						title : _this.find(".spec_title").val(),
						virtual : ""
					};
					specs.push(spec);
				});

				var len = specs.length;

				var newlen = 1;
				var h = new Array(len);

				for (var m = 0; m < len; m++) {
					h[m] = {
						title : specs[m].title,
						virtual : specs[m].virtual,
						html : "",
						id : specs[m].id
					};
				}

				var hh = '<input name="kw" type="hidden"  value="1"/>';

				for (var i = 0; i < len; i++) {
					var html = '<table class="table table-bordered table-condensed skuTable"><thead><tr class="active">';
					html += "<th style='width:80px;'></th>";
					html += '<th class="info" style="width:130px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">库存</div><div class="input-group"><input type="text" class="form-control option_stock_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
					html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">销售价格</div><div class="input-group"><input type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
					html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">市场价格</div><div class="input-group"><input type="text" class="form-control option_productprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
					html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">重量（克）</div><div class="input-group"><input type="text" class="form-control option_weight_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
					html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店佣金（元）</div><div class="input-group"><input type="text" class="form-control option_headcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_headcommission\');"></a></span></div></div></th>';
					html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店推荐人佣金（元）</div><div class="input-group"><input type="text" class="form-control option_superiorcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_superiorcommission\');"></a></span></div></div></th>';
					html += '</tr></thead>';
					hh += "<tr>";
					var ids = [];
					var titles = [];
					var virtuals = [];

					ids = ids.join('_');

					titles = titles.join('+');

					var val = {
						id : "",
						title : titles,
						stock : "",
						productprice : "",
						marketprice : "",
						weight : "",
						superiorcommission : "",
						headcommission : "",
						headtype : "",
						superiortype : "",
						virtual : virtuals
					};
					if ($(".option_id_" + ids).length > 0) {
						val = {
							id : $(".option_id_" + ids + ":eq(0)").val(),
							title : titles,
							stock : $(".option_stock_" + ids + ":eq(0)").val(),
							productprice : $(
									".option_productprice_" + ids + ":eq(0)")
									.val(),
							marketprice : $(
									".option_marketprice_" + ids + ":eq(0)")
									.val(),
							weight : $(".option_weight_" + ids + ":eq(0)")
									.val(),
							superiorcommission : $(
									".option_superiorcommission_" + ids
											+ ":eq(0)").val(),
							headcommission : $(
									".option_headcommission_" + ids + ":eq(0)")
									.val(),
							headtype : $(".option_headtype_" + ids + ":eq(0)")
									.val(),
							superiortype : $(
									".option_superiortype_" + ids + ":eq(0)")
									.val(),
							virtual : virtuals,
							specs : ids
						}
					}
					hh += "<td style='width:80px;'>" + specs[i].title + "</td>";
					hh += '<td class="info">'
							+ '<input name="option_stock_'
							+ specs[i].id
							+ '[]"type="text" class="form-control option_stock option_stock_'
							+ specs[i].id + '" value="'
							+ (val.stock == 'undefined' ? '' : val.stock)
							+ '"/></td>';
					hh += '<input name="option_id_'
							+ specs[i].id
							+ '[]"type="hidden" class="form-control option_id option_id_'
							+ specs[i].id + '" value="'
							+ (val.id == 'undefined' ? '' : val.id) + '"/>';
					hh += '<input name="option_ids[]"type="hidden" class="form-control option_ids option_ids_' + specs[i].id + '" value="' + specs[i].id + '"/>';
					hh += '<input type="hidden" class="form-control option_ids option_specs_' + specs[i].id + '" value="' + val.specs + '"/>';
					hh += '<input name="option_title_'
							+ specs[i].id
							+ '[]"type="hidden" class="form-control option_title option_title_'
							+ specs[i].id + '" value="'
							+ (val.title == 'undefined' ? '' : specs[i].title)
							+ '"/></td>';
					/* hh += '<input name="option_virtual_' + specs[i].id + '[]"type="hidden" class="form-control option_title option_title_' + specs[i].id + '" value="' + (val.virtual == 'undefined' ? '': val.virtual) + '"/></td>'; */
					hh += '</td>';
					hh += '<td class="success"><input name="option_marketprice_'
							+ specs[i].id
							+ '[]" type="text" class="form-control option_marketprice option_marketprice_'
							+ specs[i].id
							+ '" value="'
							+ (val.marketprice == 'undefined' ? ''
									: val.marketprice) + '"/></td>';
					hh += '<td class="warning"><input name="option_productprice_'
							+ specs[i].id
							+ '[]" type="text" class="form-control option_productprice option_productprice_'
							+ specs[i].id
							+ '" " value="'
							+ (val.productprice == 'undefined' ? ''
									: val.productprice) + '"/></td>';
					hh += '<td class="info"><input name="option_weight_'
							+ specs[i].id
							+ '[]" type="text" class="form-control option_weight option_weight_'
							+ specs[i].id + '" " value="'
							+ (val.weight == 'undefined' ? '' : val.weight)
							+ '"/></td>';
					//hh += '<td class="info"><input name="option_headcommission_' + specs[i].id  +'[]" type="text" class="form-control option_headcommission option_headcommission_' + specs[i].id  +'" " value="' +(val.headcommission=='undefined'?'':val.headcommission )+'"/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_superiorcommission\');"></a></span></td>';
					hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_headcommission_'
							+ specs[i].id
							+ '[]" type="text" class="form-control option_headcommission option_headcommission_'
							+ specs[i].id
							+ '" " value="'
							+ (val.headcommission == 'undefined' ? ''
									: val.headcommission)
							+ '"/><span class="input-group-addon" style="padding:0px;"><select  name="option_headtype_' + specs[i].id + '[]" type="text" class="option_headtype option_headtype_' + specs[i].id + '"  style="border-style:solid; border-color:#FFF"  ><option value="0"  >元</option><option value="1"  >%</option></select></span></div></div></td>';
					hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_superiorcommission_'
							+ specs[i].id
							+ '[]" type="text" class="form-control option_superiorcommission option_superiorcommission_'
							+ specs[i].id
							+ '" " value="'
							+ (val.superiorcommission == 'undefined' ? ''
									: val.superiorcommission)
							+ '"/><span class="input-group-addon" style="padding:0px;"><select  name="option_superiortype_' + specs[i].id + '[]" type="text" class="option_superiortype option_superiortype_' + specs[i].id + '"  style="border-style:solid; border-color:#FFF"  ><option value="0"  >元</option><option value="1"  >%</option></select></span></div></div></td>';
					hh += "</tr>";
				}
				html += hh;
				html += "</table>";
				$("#options").html(html);
			} else {
				optionchanged = false;
				var html = '<table class="table table-bordered table-condensed skuTable"><thead><tr class="active">';
				var specs = [];
				if ($('.spec_item').length <= 0) {
					$("#options").html('');
					return;
				}
				$(".spec_item")
						.each(
								function(i) {
									var _this = $(this);

									var spec = {
										id : _this.find(".spec_id").val(),
										title : _this.find(".spec_title").val()
									};

									var items = [];
									_this
											.find(".spec_item_item")
											.each(
													function() {
														var __this = $(this);
														var item = {
															id : __this
																	.find(
																			".spec_item_id")
																	.val(),
															title : __this
																	.find(
																			".spec_item_title")
																	.val(),
															virtual : __this
																	.find(
																			".spec_item_virtual")
																	.val(),
															specItemHiddesId : __this
																	.find(
																			".spec_item_title")
																	.attr(
																			"data-index")
														/* show: __this.find(".spec_item_show").get(0).checked ? "1": "0" */
														}
														items.push(item);
													});
									spec.items = items;
									specs.push(spec);
								});

				specs.sort(function(x, y) {
					if (x.items.length > y.items.length) {
						return 1;
					}
					if (x.items.length < y.items.length) {
						return -1;
					}
				});

				var len = specs.length; //规格数量
				var newlen = 1; // 所有规格项组合数量
				var h = new Array(len);
				var rowspans = new Array(len);
				for (var i = 0; i < len; i++) {
					html += "<th style='width:80px;'>" + specs[i].title
							+ "</th>";
					var itemlen = specs[i].items.length;
					if (itemlen <= 0) {
						itemlen = 1
					}
					;
					newlen *= itemlen;
					h[i] = new Array(newlen);
					for (var j = 0; j < newlen; j++) {
						h[i][j] = new Array();
					}
					var l = specs[i].items.length;
					rowspans[i] = 1;
					for (j = i + 1; j < len; j++) {
						rowspans[i] *= specs[j].items.length;
					}
				}

				html += '<th class="info" style="width:130px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">库存</div><div class="input-group"><input type="text" class="form-control option_stock_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
				html += '<th class="success" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">销售价格</div><div class="input-group"><input type="text" class="form-control option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
				html += '<th class="warning" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">市场价格</div><div class="input-group"><input type="text" class="form-control option_productprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
				html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">重量（克）</div><div class="input-group"><input type="text" class="form-control option_weight_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
				html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店佣金（元）</div><div class="input-group"><input type="text" class="form-control option_headcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_headcommission\');"></a></span></div></div></th>';
				html += '<th class="info" style="width:150px;"><div class=""><div style="padding-bottom:10px;text-align:center;font-size:16px;">门店推荐人佣金（元）</div><div class="input-group"><input type="text" class="form-control option_superiorcommission_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-hand-o-down" title="批量设置" onclick="setCol(\'option_superiorcommission\');"></a></span></div></div></th>';
				html += '</tr></thead>';

				for (var m = 0; m < len; m++) {
					var k = 0, kid = 0, n = 0;
					for (var j = 0; j < newlen; j++) {
						var rowspan = rowspans[m];

						h[m][j] = {
							title : specs[m].items[kid].title,
							virtual : specs[m].items[kid].virtual,
							// html: "<td rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
							html : "<td>" + specs[m].items[kid].title
									+ "</td>\r\n",
							id : specs[m].items[kid].id,
							specItemHiddesId : specs[m].items[kid].specItemHiddesId
						};
						/* if (j % rowspan == 0) {
						    h[m][j] = {
						        title: specs[m].items[kid].title,
						        virtual: specs[m].items[kid].virtual,
						        // html: "<td rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
						        html: "<td>" + specs[m].items[kid].title + "</td>\r\n",
						        id: specs[m].items[kid].id,
						        specItemHiddesId: specs[m].items[kid].specItemHiddesId
						    };
						} else {
						    h[m][j] = {
						        title: specs[m].items[kid].title,
						        virtual: specs[m].items[kid].virtual,
						        html: "",
						        id: specs[m].items[kid].id,
						        specItemHiddesId: specs[m].items[kid].specItemHiddesId
						    };
						} */
						n++;
						if (n == rowspan) {
							kid++;
							if (kid > specs[m].items.length - 1) {
								kid = 0;
							}
							n = 0;
						}
					}
				}

				var hh = '<input name="kw" type="hidden"  value="0"/>';
				for (var i = 0; i < newlen; i++) {

					hh += "<tr>";
					var ids = [];
					var titles = [];
					var virtuals = [];
					var specItemHiddenIds = [];
					for (var j = 0; j < len; j++) {
						hh += h[j][i].html;
						ids.push(h[j][i].id);
						titles.push(h[j][i].title);
						specItemHiddenIds.push(h[j][i].specItemHiddesId); // 建立specItem和sku之间的关系
						virtuals.push(h[j][i].virtual);
					}
					ids = ids.join('_');
					titles = titles.join('+');
					specItemHiddenIds = specItemHiddenIds.join('_');

					var val = {
						id : "",
						title : titles,
						stock : "",
						productprice : "",
						marketprice : "",
						weight : "",
						superiorcommission : "",
						headcommission : "",
						virtual : virtuals,
						specItemHiddenIds : specItemHiddenIds
					};
					if ($(".option_id_" + ids).length > 0) {
						val = {
							id : $(".option_id_" + ids + ":eq(0)").val(),
							title : titles,
							specItemHiddenIds : specItemHiddenIds,
							stock : $(".option_stock_" + ids + ":eq(0)").val(),
							productprice : $(
									".option_productprice_" + ids + ":eq(0)")
									.val(),
							marketprice : $(
									".option_marketprice_" + ids + ":eq(0)")
									.val(),
							weight : $(".option_weight_" + ids + ":eq(0)")
									.val(),
							superiorcommission : $(
									".option_superiorcommission_" + ids
											+ ":eq(0)").val(),
							headcommission : $(
									".option_headcommission_" + ids + ":eq(0)")
									.val(),
							headtype : $(".option_headtype_" + ids + ":eq(0)")
									.val(),
							superiortype : $(
									".option_superiortype_" + ids + ":eq(0)")
									.val(),
							virtual : virtuals
						}
					}
					hh += '<td class="info">'
							+ '<input name="option_stock_'
							+ ids
							+ '[]"type="text" class="form-control option_stock option_stock_'
							+ ids + '" value="'
							+ (val.stock == 'undefined' ? '' : val.stock)
							+ '"/></td>';
					hh += '<input name="option_id_'
							+ ids
							+ '[]"type="hidden" class="form-control option_id option_id_'
							+ ids + '" value="'
							+ (val.id == 'undefined' ? '' : val.id) + '"/>';
					hh += '<input name="option_ids[]" type="hidden" class="form-control option_ids option_ids_' + ids + '" value="' + ids + '"/>';
					hh += '<input type="hidden" class="form-control option_title option_title_'
							+ ids
							+ '" value="'
							+ (val.title == 'undefined' ? '' : val.title)
							+ '"/></td>';
					hh += '<input type="hidden" class="form-control option_specItemHiddenId" value="'
							+ (val.specItemHiddenIds == 'undefined' ? ''
									: val.specItemHiddenIds) + '"/></td>';
					/* hh += '<input name="option_virtual_' + ids + '[]"type="hidden" class="form-control option_title option_title_' + ids + '" value="' + (val.virtual == 'undefined' ? '': val.virtual) + '"/></td>'; */
					hh += '</td>';
					hh += '<td class="success"><input name="option_marketprice_'
							+ ids
							+ '[]" type="text" class="form-control option_marketprice option_marketprice_'
							+ ids
							+ '" value="'
							+ (val.marketprice == 'undefined' ? ''
									: val.marketprice) + '"/></td>';
					hh += '<td class="warning"><input name="option_productprice_'
							+ ids
							+ '[]" type="text" class="form-control option_productprice option_productprice_'
							+ ids
							+ '" " value="'
							+ (val.productprice == 'undefined' ? ''
									: val.productprice) + '"/></td>';
					hh += '<td class="info"><input name="option_weight_'
							+ ids
							+ '[]" type="text" class="form-control option_weight option_weight_'
							+ ids + '" " value="'
							+ (val.weight == 'undefined' ? '' : val.weight)
							+ '"/></td>';
					hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_headcommission_'
							+ ids
							+ '[]" type="text" class="form-control option_headcommission option_headcommission_'
							+ ids
							+ '" " value="'
							+ (val.headcommission == 'undefined' ? ''
									: val.headcommission)
							+ '"/><span class="input-group-addon" style="padding:0px;"><select  name="option_headtype_' + ids + '[]" type="text" class="option_headtype option_headtype_' + ids + '"  style="border-style:solid; border-color:#FFF"  ><option value="0"  >元</option><option value="1"  >%</option></select></span></div></div></td>';
					hh += '<td class="info" style="width:150px;"><div class=""><div class="input-group"><input name="option_superiorcommission_'
							+ ids
							+ '[]" type="text" class="form-control option_superiorcommission option_superiorcommission_'
							+ ids
							+ '" " value="'
							+ (val.superiorcommission == 'undefined' ? ''
									: val.superiorcommission)
							+ '"/><span class="input-group-addon" style="padding:0px;"><select  name="option_superiortype_' + ids + '[]" type="text" class="option_superiortype option_superiortype_' + ids + '"  style="border-style:solid; border-color:#FFF"  ><option value="0"  >元</option><option value="1">%</option></select></span></div></div></td>';
					hh += "</tr>";
				}
				html += hh;
				html += "</table>";
				$("#options").html(html);
			}
		}

		function setCol(cls) {
			$("." + cls).val($("." + cls + "_all").val());
		}

		var optionchanged = false;
		function updateProduct() {
			var specs = [];
			// 组装规格和规格属性
			if ($('.spec_item').length > 0) {
				$(".spec_item").each(
						function(i) {
							var specItems = [];
							var _this = $(this);
							$(_this.find(".spec_item_item")).each(
									function(i) {
										var _specItemItem = $(this);
										var specItem = {
											title : _specItemItem.find(
													'.spec_item_title').val(),
											thumb : _specItemItem
													.find('.thumb').val(),
											specItemHiddenId : _specItemItem
													.find('.spec_item_title')
													.attr('data-index'),
										}
										specItems.push(specItem);
									})
							var spec = {
								title : _this.find(".spec_title").val(),
								specItemList : specItems
							};
							specs.push(spec); // 设置规格
						})
				/* console.info(specs); */
			}

			// 遍历sku，组装sku
			var skuList = [];
			$(".skuTable tbody tr").each(
					function() {
						var _this = $(this);
						var sku = {
							title : _this.find(".option_title").val(),
							specItemHiddenId : _this.find(
									".option_specItemHiddenId").val(),
							productprice : _this.find(".option_productprice")
									.val(),
							marketprice : _this.find(".option_marketprice")
									.val(),

							stock : _this.find(".option_stock").val(),
							weight : _this.find(".option_weight").val(),
							headcommission : _this.find(
									".option_headcommission").val(),
							headtype : _this.find(".option_headtype").val(),
							superiorcommission : _this.find(
									".option_superiorcommission").val(),
							superiortype : _this.find(".option_superiortype")
									.val(),
						}
						skuList.push(sku);
					})

			if ($("#title").val() == '' || $("#title").val() == undefined) {
				layer.alert("请输入商品名称!", {icon: 5});
				return false;
			}

			if ($.trim($(':input[name="thumb"]').val()) == '') {
				layer.alert("请上传缩略图!", {icon: 5});
				return false;
			}

			/*if ($("#manudate").val() == '' || $("#manudate").val() == undefined) {
                layer.alert("请选择商品生产日期!", {icon: 5});
                return false;
            }

            if ($("#guarantday").val() == '' || $("#guarantday").val() == undefined) {
                layer.alert("请填写商品保质期!", {icon: 5});
                return false;
            }*/

			if ($("#marketprice").val() == '' || $("#marketprice").val() == undefined) {
				layer.alert("请输入商品现价!", {icon: 5});
				return false;
			}
			if ($("#productprice").val() == '' || $("#productprice").val() == undefined) {
				layer.alert("请输入商品原价!", {icon: 5});
				return false;
			}
			if ($("#costprice").val() == '' || $("#costprice").val() == undefined) {
				layer.alert("请输入商品成本价!", {icon: 5});
				return false;
			}
			if ($("#weight").val() == '' || $("#weight").val() == undefined) {
				layer.alert("请输入商品重量!", {icon: 5});
				return false;
			}
			if ($("#total").val() == '' || $("#total").val() == undefined) {
				layer.alert("请输入商品库存!", {icon: 5});
				return false;
			}

			var full = true;
			full = checkoption();
			if (!full) {
				return false;
			}
			if (optionchanged) {
				layer.alert("规格数据有变动，请重新点击 [刷新规格项目表] 按钮!", {
					icon : 5
				});
				return false;
			}
			var id = $("#id").val(); // 商品id
			var displayorder = $("#displayorder").val();
			if (displayorder > 2147483647) {
				layer.msg("排序值过大");
				return;
			}
			var title = $("#title").val();
			var shortTitle = $("#shortTitle").val();
			var goodscode = $("#goodscode").val();
			var specTitle = $("#specTitle").val();
			var pcate = $("#pcate").val();
			var ccate = $("#ccate").val();
			var supplierId = $("#supplierId").val();
			var unit = $("#unit").val();
			var isrecommand = $("input[name='isrecommand']:checked").val();
			var isnew = $("input[name='isnew']:checked").val();
			var isTeamBuy = $("input[name='isTeamBuy']:checked").val();
			var ishot = $("input[name='ishot']:checked").val();
			var isdiscount = $("input[name='isdiscount']:checked").val();
			var istime = $("input[name='istime']:checked").val();
			var ismiaosha = $("input[name='ismiaosha']:checked").val();
			var islimited = $("input[name='islimited']:checked").val();

			var isbig = $("input[name='isbig']:checked").val();
			var iszhicai = $("input[name='iszhicai']:checked").val();
			var ismao = $("input[name='ismao']:checked").val();
			var isfanchang = $("input[name='isfanchang']:checked").val();
			/* var isgerida = $("input[name='isgerida']:checked").val(); */
			var isfashi = $("input[name='isfashi']:checked").val();
			var iszhutihuakuang = $("input[name='iszhutihuakuang']:checked")
					.val();

			var selfvalue = $("#selfvalue").val();
			var timestart = $("#timestart").val();
			var timeend = $("#timeend").val();

			var thumb = $("#thumb").val();
			var thumbSquare = $("#thumbSquare").val();
			var videourl = $("#videourl").val();
			var thumbUrl = $("#thumbUrl").val();
			var marketprice = $("#marketprice").val();//现价
			var startLimit = $("#startLimit").val();//最低量
			var productprice = $("#productprice").val();//原价
			var costprice = $("#costprice").val();//成本价
			var suggestsaleprice = $("#suggestsaleprice").val();//建议零售价
			var weight = $("#weight").val();
			var total = $("#total").val();
			var maxbuy = $("#maxbuy").val();
			var usermaxbuy = $("#usermaxbuy").val();

			var sales = $("#sales").val();
			var viewcount = $("#viewcount").val();
			var credit = $("#credit").val();
			var status = $('input[name="status"]:checked').val();
			var isgongyi = $('input[name="isgongyi"]:checked').val();
			if (isgongyi == 1) {
				var gongyiprice = $("#gongyiprice").val();
			}
			var areas = $("#selectedareas").val();
			var showsupply = $('input[name="showsupply"]:checked').val();
			var uncancelable = $('input[name="uncancelable"]:checked').val();
			var description = UE.getEditor('content').getContent();
			var tihuoday = $("#tihuoday").val();
			var freeShipping = $('input[name="free_shipping"]:checked').val();
			var sendprice = $("#sendprice").val(); // 独立邮费
			var dispatchid = $("#dispatchid").val(); // 邮费模板
			var manudate = $("#manudate").val();
			var guarantday = $("#guarantday").val();
			var isFxCommission = 0; //是否开启门店佣金
			if ($('#is_fx_commission').is(':checked')) {
				isFxCommission = 1;
			}
			var headcommission = $("#headcommission").val(); //门店佣金设置
			var headtype = $("#headtype").val();
			var superiorcommission = $("#superiorcommission").val();
			var superiortype = $("#superiortype").val();
			var proddes = $("#proddes").val();
			var data = {
				"id" : id,
				"displayorder" : displayorder,
				"goodscode" : goodscode,
				"specTitle" : specTitle,
				"pcate" : pcate,
				"ccate" : ccate,
				"supplierId" : supplierId,
				"isrecommand" : isrecommand,
				"title" : title,
				"shortTitle" : shortTitle,
				"unit" : unit,
				"selfvalue" : selfvalue,
				"timestart" : timestart,
				"timeend" : timeend,
				"thumb" : thumb,
				"thumbSquare" : thumbSquare,
				"videourl" : videourl,
				"thumbUrl" : thumbUrl,
				"marketprice" : marketprice,
				"startLimit" : startLimit,
				"productprice" : productprice,
				"suggestsaleprice" : suggestsaleprice,
				"weight" : weight,
				"total" : total,
				"maxbuy" : maxbuy,
				"usermaxbuy" : usermaxbuy,
				"sales" : sales,
				"status" : status,
				"isgongyi" : isgongyi,
				"viewcount" : viewcount,
				"gongyiprice" : gongyiprice,
				"showsupply" : showsupply,
				"uncancelable" : uncancelable,
				"areas" : areas,
				"description" : description,
				"freeShipping" : freeShipping,
				"sendprice" : sendprice,
				"dispatchid" : dispatchid,
				"isFxCommission" : isFxCommission,
				"headcommission" : headcommission,
				"headtype" : headtype,
				"superiorcommission" : superiorcommission,
				"superiortype" : superiortype,
				"tihuoday" : tihuoday,
				"manudate" : manudate,
				"guarantday" : guarantday,
				"proddes" : proddes,
				"costprice":costprice,
				"credit":credit
			};
			data.specList = specs;
			data.skuList = skuList;
			if (isrecommand == 1)
				data.isrecommand = 1; else data.isrecommand = 0;
			if (isnew == 1)
				data.isnew = 1; else data.isnew = 0;
			if (isTeamBuy == 1)
				data.isTeamBuy = 1; else data.isTeamBuy = 0;
			if (ishot == 1)
				data.ishot = 1;else data.ishot = 0;
			if (isdiscount == 1)
				data.isdiscount = 1;else data.isdiscount = 0;
			if (ismiaosha == 1)
				data.ismiaosha = 1; else data.ismiaosha = 0;
			if (islimited == 1)
				data.islimited = 1;else data.islimited = 0;
			if (istime == 1)
				data.istime = 1;else data.istime = 0;
			if (iszhicai == 1)
				data.iszhicai = 1;else 	data.iszhicai = 0;
			if (ismao == 1)
				data.ismao = 1;else data.ismao = 0;
			if (isfanchang == 1)
				data.isfanchang = 1;else data.isfanchang = 0;
			/* if (isgerida == 1) data.isgerida=1; */
			if (isfashi == 1)
				data.isfashi = 1;else data.isfashi = 0;
			if (iszhutihuakuang == 1)
				data.iszhutihuakuang = 1;else data.iszhutihuakuang = 0;
			if (isbig == 1)
				data.isbig = 1;else data.isbig = 0;

			var hasoption = $("input[name='hasoption']:checked").val();
			var secondSpec = $("input[name='second_spec']:checked").val();
			if (hasoption == 1)
				data.hasoption = 1;
			else
				data.hasoption = 0;
			if (secondSpec == 1)
				data.hasoptionsbuy = 1;
			else
				data.hasoptionsbuy = 0;
			if (status == 2) {
				data.upStartTime = $("#upStartTime").val();
				data.upEndTime = $("#upEndTime").val();
			}

			$.ajax({
				url : '/product/data/update',
				contentType : "application/json",
				dataType : "json",
				type : 'POST',
				data : JSON.stringify(data),
				success : function(result) {
					if (result.code == 0) {
						parent.layer.msg("保存成功", {
							icon : 6
						});
						var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
						// parent.reLoad();
						parent.layer.close(index);
					} else {
						parent.layer.alert("保存失败，请联系管理员", {
							icon : 5
						});
					}
				}
			})
		}

		function checkoption() {
			var full = true;
			if ($("#hasoption").get(0).checked) {
				$(".spec_title").each(function(i) {
					if ($(this).val() == '' || $(this).val() == undefined) {
						layer.alert("请输入规格名称!", {
							icon : 5
						});
						full = false;
						return false;
					}
				});
				$(".spec_item_title").each(function(i) {
					if ($(this).val() == '' || $(this).val() == undefined) {
						layer.alert("请输入规格项名称!", {
							icon : 5
						});
						full = false;
						return false;
					}
				});
			}
			if (!full) {
				return false;
			}
			return full;
		}

		function onSelectImgBtnClick(inputId, imgId) {
			layer.open({
				id : 'selectImg',
				type : 2,
				title : '选择图片',
				maxmin : true,
				shadeClose : false,
				area : [ '60%', '70%' ],
				content : '/platform/config/selectImg/' + inputId + "/" + imgId // iframe的url
			});
		}

		function onSelectVideoBtnClick(inputId, imgId) {
			layer.open({
				id : 'selectImg',
				type : 2,
				title : '选择视频',
				maxmin : true,
				shadeClose : false,
				area : [ '60%', '70%' ],
				content : '/platform/config/selectVideo/' + inputId + "/"
						+ imgId // iframe的url
			});
		}

		/**
		 * 加载图片URL
		 * @param inputId
		 * @param imgId
		 * @param url
		 */
		function loadImgUrl(inputId, imgId, url) {
			$('#' + inputId + '').val(url);
			$('#' + imgId + '').attr('src', url);
		}

		// 批量上传图片
		function selectImgs(domId) {
			layer.open({
				id : 'selectImgs',
				type : 2,
				title : '批量选择图片',
				maxmin : true,
				shadeClose : false,
				area : [ '60%', '70%' ],
				content : '/platform/config/batchUploadImg/' + domId // iframe的url
			});
		}

		function loadImgsInfo(domId, result) {
			if (!result || result.length < 1) {
				layer.msg(result.msg, {
					icon : 7
				});
				return;
			}
			$('#thumbUrl').val(result.join(","));
		}

		// 加载图片进ueditor中
		function loadImgsToUeditor(result) {
			if (!result || result.length < 1) {
				layer.msg(result.msg, {
					icon : 7
				});
				return;
			}
			console.info(result);
			/* var imgUrlArray = result.split(","); */
			let editor = UE.getEditor('content');
			for (var i = 0; i < result.length; i++) {
				var imgUrl = result[i];
				editor.execCommand('inserthtml', `<img src=${imgUrl}>`);
			}
		}
	</script>

</body>
</html>
